home *** CD-ROM | disk | FTP | other *** search
- Path: access4.digex.net!not-for-mail
- From: ell@access4.digex.net (Ell)
- Newsgroups: comp.lang.c++
- Subject: [Q] [enums] class_ID as enum is basically use
- Date: 23 Jan 1996 05:22:15 GMT
- Organization: The Universe
- Message-ID: <4e1ra7$avi@news4.digex.net>
- NNTP-Posting-Host: access4.digex.net
- X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
-
- (ell@access2.digex.net) wrote:
- : Robert C. Martin (rmartin@oma.com) wrote:
- : :...
- : : Often, you don't need a virtual function to expose the type, because
- : : the type is set in the constructor, and all objects derived from that
- : : the base class that defines the enum inherit the member variable.
- : :
- : : class X
- : : {
- : : public:
- : : enum Type {x1, x2};
- : : Type itsType;
- : : };
- : :
- : : class X1 : public X
- : : {
- : : public:
- : : X1() : itsType(x1) {}
- : : };
- : :
- : : class X2 : public X
- : : {
- : : public:
- : : X2() : itsType(x2);
- : : }
- : :
- : : X* xp = new X2;
- : : assert(xp->itsType == X::x2);
-
- : : The above example should convince you that a virtual function isn't
- : : necessary. That any object derived from X will have the correct enum
- : : in its itsType variable, and that any client can get this variable
- : : through the X interface and interrogate it.
-
- : While Lippman agrees with your point that derived classes should see a
- : public (or protected) data member of the base class, the VC++ compiler
- : version 1.5 does not. The VC++ compiler gives the error that 'itsType' is
- : not a function or member of the derived classes. I'm guessing that the
- : VC++ compiler is wrong. Anyone care to straighten this out?
- :
- : Elliott
-
- Surprise! When assignment rather than member initialization is used with
- Visual C++ 1.5, the above works. Seems that while public parent data can
- be accessed by derived classes, as any other class can, contrary to the
- ARM of '92, they are not considered "inherited" members by VC 1.5. So
- member initialization semantics can not be used. Anyone care to try this
- on VC++ 4.0? Would anyone care to explain this behavior by VC++ 1.5?
-
- Elliott
-